package main

import ("fmt"
"time"
)

func writeData(intChan chan int) {
 for i:=1;i<=50;i++ {
		intChan <- i
		fmt.Println("writeData:",i)
 }
 close(intChan)
}

func readData(intChan chan int,exitChan chan bool) {
	for i:=range intChan {
		time.Sleep(time.Second)
		fmt.Printf("readeData:%v\n",i)
	}
	// 读取完数据任务完成
	exitChan <- true
	close(exitChan)
}

func main() {
  intChan := make(chan int,10)
  exitChan := make(chan bool,1)
	go writeData(intChan)
	go readData(intChan,exitChan)
	for {
		_,ok := <- exitChan
		if !ok {
			break
		} 
	}
}

